from django.forms.models import model_to_dict

def utils_model_to_dict(model, *args, **kwargs):
    data = model_to_dict(model)
    data["user_id"] = str(model.user_id)
    # 头像
    data["avatar"] = model.avatar.url if model.avatar else None
    data["role"] = {
        "code": model.role,
        "message": model.get_role_display()
    }
    data["status"] = {
        "code": model.status,
        "message": model.get_status_display()
    }
    data["create_time"] = model.create_time.strftime("%Y-%m-%d %H:%M:%S")
    data["update_time"] = model.update_time.strftime("%Y-%m-%d %H:%M:%S")
    if kwargs.get("show_password", False) is False:
        del data["password"]


    return data